import sys

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *

class  QDialogDemo(QMainWindow):

    def __init__(self):
        super(QDialogDemo, self).__init__()

        self.initUI()
    def initUI(self):

        self.setWindowTitle('QDialog 案例')
        self.resize(300,300)
        Layout = QVBoxLayout()

        self.button = QPushButton(self)
        self.button.setText("弹出对话框")
        self.button.move(50,50)
        self.button.clicked.connect(self.showDialog)

        Layout.addWidget(self.button)
        self.setLayout(Layout)
    def showDialog(self):

        dialog = QDialog()
        btn = QPushButton('稳定', dialog)
        btn.clicked.connect(dialog.close)
        btn.move(50, 50)
        dialog.setWindowTitle('对话框')
        dialog.setWindowModality(Qt.ApplicationModal)

        dialog.exec_()
if __name__ == '__main__':

    app = QApplication(sys.argv)
    ex = QDialogDemo()
    ex.show()
    sys.exit(app.exec_())